package com.darrenchan.netease04

/**
  * 函数和方法都可以当做彼此的参数
  *
  */
object Method_Function {
  def main(args: Array[String]): Unit = {
    println(m1(1, 2)) //3
    println(f1(1, 2)) //3


    println(mm1(3, 4, f1)) //7
    println(mm1(3, 4, m1)) //7
    println(mm1(3, 4, m1 _)) //7
    println(mm1(3, 4, f2)) //7
  }

  //方法
  def m1(x: Int, y: Int) = x + y

  //函数
  val f1: (Int, Int) => Int = (x: Int, y: Int) => x + y
  val f2 = m1 _ //转成方法


  def mm1(x: Int, y: Int, ff: (Int, Int) => Int) = {
    ff(x, y)
  }
}
